package com.cgwx.common.enums;

import com.cgwx.common.utils.EnumUtils;

import java.util.Optional;

/**
 * 试验状态
 */
public enum LockState implements InfoEnum{
    TEMP_LOCK("暂时锁定","TEMP_LOCK"),
    NORMAL_LOCK("正式锁定","NORMAL_LOCK"),
    QUEUE_TEMP_LOCK("暂时插队锁定","QUEUE_TEMP_LOCK"),
    QUEUE_LOCK("插队正式锁定","QUEUE_LOCK"),
    URGENT_TEMP_LOCK("加急暂时锁定","URGENT_TEMP_LOCK"),
    URGENT_LOCK("加急正式锁定","URGENT_LOCK"),
    ADMIN_LOCK("管理员锁定","ADMIN_LOCK"),
    ADMIN_CANCEL("管理员取消","ADMIN_CANCEL"),
    CANCEL("申请取消","CANCEL"),
    OUT_OF_TIME("超过锁定时间","OUT_OF_TIME"),
    ADMIN_UNLOCK("管理员解锁","ADMIN_UNLOCK")
    ;

    String info;
    String code;

    public String getInfo() {
        return info;
    }

    public String getCode() {
        return code;
    }

    LockState(String info, String code) {
        this.info = info;
        this.code = code;
    }

    public static String getCodeByExperimentState(String experimentState){
        Optional<LockState> m1 = EnumUtils.getEnumObject(LockState.class, e -> e.getCode().equals(experimentState));
        return m1.isPresent() ? m1.get().getCode() : null;
    }


    @Override
    public String getSelfCode() {
        return this.code;
    }

    @Override
    public String getSelfInfo() {
        return this.info;
    }

    private static LockState[] vals = values();

    // 是否有上一个
    public boolean hasPrevious() {
        if (this.ordinal() <= 0) {
            return false;
        }
        return true;
    }

    // 是否有下一个
    public boolean hasNext() {
        if(this.ordinal() >= vals.length - 1) {
            return false;
        }
        return true;
    }

    // 上一个
    public LockState previous() {
        return vals[(this.ordinal() - 1) % vals.length];
    }

    //下一个
    public LockState next() {
        return vals[(this.ordinal() + 1) % vals.length];
    }

}
